﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Vtron.ATSP.DataAccess;
using Vtron.ATSP.DomainObjects;
using Vtron.ATSP.Projector;
using Vtron.ATSP.Tester;

namespace Vtron.ATSP.BusinessLogic
{
    /// <summary>
    /// 屏幕测试的处理类
    /// </summary>
    /// <remarks>
    ///     <创建人>邓穗捷</创建人>
    ///     <创建时间>2014-08-19</创建时间>
    ///     <修订人></修订人>
    ///     <修订时间></修订时间>
    ///     <修订说明></修订说明>
    /// </remarks>
    public class ScreenTestHandler
    {
        #region Fields

        private const byte SENSORNUMBER = 65;
        private IProjectorCom IProjectorCom;
        private ISerialCom ISerialCom;
        private IPersistence IPersistence;

        #endregion

        #region Constructor

        public ScreenTestHandler(IProjectorCom IProjectorCom, ISerialCom ISerialCom, IPersistence IPersistence)
        {
            this.IProjectorCom = IProjectorCom;
            this.ISerialCom = ISerialCom;
            this.IPersistence = IPersistence;
        }

        #endregion

        #region Private Helper Methods

        /// <summary>
        /// 先决条件
        ///     不符合先决条件则抛出 Vtron.ATSP.DomainObjects.ATSPException 异常。
        /// </summary>
        private void Precondition()
        {
            if (IProjectorCom == null)
            {
                throw new ATSPException("IProjectorCom 不能为 null。");
            }

            if (ISerialCom == null)
            {
                throw new ATSPException("ISerialCom 不能为 null。");
            }
        }

        /// <summary>
        /// 针对一种颜色做校准
        /// </summary>
        /// <param name="deviceNum">设备号</param>
        /// <param name="CLight">亮场值</param>
        /// <param name="color">暗场值</param>
        /// <param name="color">需要校准的颜色</param>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-08-19</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        private void Adust(byte deviceNum, double CLight, double CDark, Color color)
        {
            if (!IProjectorCom.SetDesktop(color))
            {
                throw new ATSPException("设置桌面失败！");
            }

            Calibration calibration = IPersistence.GetCalibration(deviceNum);
            if (!ISerialCom.SetADC(calibration.Range))
            {
                throw new ATSPException(String.Format("设置ADC参数指令失败！设备号{0}", deviceNum));
            }
            Sensor sensorLight = ISerialCom.GetSensor(deviceNum);


            List<Sensor> sensorDarks = new List<Sensor>();
            if (!IProjectorCom.SetDesktop(Color.Black))
            {
                throw new ATSPException("设置桌面失败！");
            }

            Sensor sensorDark = ISerialCom.GetSensor(deviceNum);

            if (sensorLight.CollectionValue == sensorDark.CollectionValue)
            {
                throw new ATSPException("计算K值失败！从测试仪获取到的亮场值和暗场值相同，请检查环境光影响或测试仪故障。");
            }
            else if (sensorLight.CollectionValue < sensorDark.CollectionValue)
            {
                throw new ATSPException("计算K值失败！从测试仪获取到的亮场值小于暗场值，请检查环境光影响或测试仪故障。");
            }

            double K = (CLight - CDark) / (sensorLight.CollectionValue - sensorDark.CollectionValue);
            double B = sensorDark.CollectionValue;

            calibration.K = K;
            calibration.B = B;

            if (!IPersistence.SaveCalibration(calibration))
            {
                throw new ATSPException("保存校准参数类的集合失败！");
            }
        }

        /// <summary>
        /// 针对一种颜色做测试
        /// </summary>
        /// <param name="brightness">参考亮度值</param>
        /// <param name="color">需要测试的颜色</param>
        /// <param name="acceptanceCondition">测试屏幕是否合格的判断条件</param>
        /// <returns>测试结果</returns>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-08-29</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        private TestResults Measure(double brightness, Color color, AcceptanceCondition acceptanceCondition)
        {
            if (!IProjectorCom.SetDesktop(color))
            {
                throw new ATSPException("设置桌面失败！");
            }

            TestResultsLine horizontal = new TestResultsLine();
            TestResultsLine vertical = new TestResultsLine();

            for (byte deviceNum = 0; deviceNum < SENSORNUMBER; deviceNum++)
            {
                Calibration calibration = IPersistence.GetCalibration(deviceNum);
                if (!ISerialCom.SetADC(calibration.Range))
                {
                    throw new ATSPException(String.Format("设置ADC参数指令失败！设备号{0}", deviceNum));
                }
                Sensor sensor = ISerialCom.GetSensor(deviceNum);

                double gain = Math.PI * calibration.K * (sensor.CollectionValue - calibration.B) / brightness;

                if (deviceNum == 0)
                {
                    horizontal.Angle90 = gain;
                    vertical.Angle90 = gain;
                }
                else if (deviceNum == 1)
                {
                    horizontal.Angle10 = gain;
                }
                else if (deviceNum == 2)
                {
                    horizontal.Angle15 = gain;
                    if (horizontal.Angle15 <= horizontal.Angle10)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 3)
                {
                    horizontal.Angle20 = gain;
                    if (horizontal.Angle20 <= horizontal.Angle15)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 4)
                {
                    horizontal.Angle25 = gain;
                    if (horizontal.Angle25 <= horizontal.Angle20)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 5)
                {
                    horizontal.Angle30 = gain;
                    if (horizontal.Angle30 <= horizontal.Angle25)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 6)
                {
                    horizontal.Angle35 = gain;
                    if (horizontal.Angle35 <= horizontal.Angle30)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 7)
                {
                    horizontal.Angle40 = gain;
                    if (horizontal.Angle40 <= horizontal.Angle35)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 8)
                {
                    horizontal.Angle45 = gain;
                    if (horizontal.Angle45 <= horizontal.Angle40)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 9)
                {
                    horizontal.Angle50 = gain;
                    if (horizontal.Angle50 <= horizontal.Angle45)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 10)
                {
                    horizontal.Angle55 = gain;
                    if (horizontal.Angle55 <= horizontal.Angle50)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 11)
                {
                    horizontal.Angle60 = gain;
                    if (horizontal.Angle60 <= horizontal.Angle55)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 12)
                {
                    horizontal.Angle65 = gain;
                    if (horizontal.Angle65 <= horizontal.Angle60)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 13)
                {
                    horizontal.Angle70 = gain;
                    if (horizontal.Angle70 <= horizontal.Angle65)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 14)
                {
                    horizontal.Angle75 = gain;
                    if (horizontal.Angle75 <= horizontal.Angle70)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 15)
                {
                    horizontal.Angle80 = gain;
                    if (horizontal.Angle80 <= horizontal.Angle75)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 16)
                {
                    horizontal.Angle85 = gain;
                    if (horizontal.Angle85 <= horizontal.Angle80)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                    if (horizontal.Angle90 <= horizontal.Angle85)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 17)
                {
                    horizontal.Angle95 = gain;
                    if (horizontal.Angle95 >= horizontal.Angle90)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 18)
                {
                    horizontal.Angle100 = gain;
                    if (horizontal.Angle100 >= horizontal.Angle95)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 19)
                {
                    horizontal.Angle105 = gain;
                    if (horizontal.Angle105 >= horizontal.Angle100)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 20)
                {
                    horizontal.Angle110 = gain;
                    if (horizontal.Angle110 >= horizontal.Angle105)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 21)
                {
                    horizontal.Angle115 = gain;
                    if (horizontal.Angle115 >= horizontal.Angle110)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 22)
                {
                    horizontal.Angle120 = gain;
                    if (horizontal.Angle120 >= horizontal.Angle115)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 23)
                {
                    horizontal.Angle125 = gain;
                    if (horizontal.Angle125 >= horizontal.Angle120)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 24)
                {
                    horizontal.Angle130 = gain;
                    if (horizontal.Angle130 >= horizontal.Angle125)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 25)
                {
                    horizontal.Angle135 = gain;
                    if (horizontal.Angle135 >= horizontal.Angle130)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 26)
                {
                    horizontal.Angle140 = gain;
                    if (horizontal.Angle140 >= horizontal.Angle135)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 27)
                {
                    horizontal.Angle145 = gain;
                    if (horizontal.Angle145 >= horizontal.Angle140)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 28)
                {
                    horizontal.Angle150 = gain;
                    if (horizontal.Angle150 >= horizontal.Angle145)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 29)
                {
                    horizontal.Angle155 = gain;
                    if (horizontal.Angle155 >= horizontal.Angle150)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 30)
                {
                    horizontal.Angle160 = gain;
                    if (horizontal.Angle160 >= horizontal.Angle155)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 31)
                {
                    horizontal.Angle165 = gain;
                    if (horizontal.Angle165 >= horizontal.Angle160)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 32)
                {
                    horizontal.Angle170 = gain;
                    if (horizontal.Angle170 >= horizontal.Angle165)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 33)
                {
                    vertical.Angle10 = gain;
                }
                else if (deviceNum == 34)
                {
                    vertical.Angle15 = gain;
                    if (horizontal.Angle15 <= horizontal.Angle10)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 35)
                {
                    vertical.Angle20 = gain;
                    if (horizontal.Angle20 <= horizontal.Angle15)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 36)
                {
                    vertical.Angle25 = gain;
                    if (horizontal.Angle25 <= horizontal.Angle20)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 37)
                {
                    vertical.Angle30 = gain;
                    if (horizontal.Angle30 <= horizontal.Angle25)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 38)
                {
                    vertical.Angle35 = gain;
                    if (horizontal.Angle35 <= horizontal.Angle30)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 39)
                {
                    vertical.Angle40 = gain;
                    if (horizontal.Angle40 <= horizontal.Angle35)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 40)
                {
                    vertical.Angle45 = gain;
                    if (horizontal.Angle45 <= horizontal.Angle40)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 41)
                {
                    vertical.Angle50 = gain;
                    if (horizontal.Angle50 <= horizontal.Angle45)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 42)
                {
                    vertical.Angle55 = gain;
                    if (horizontal.Angle55 <= horizontal.Angle50)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 43)
                {
                    vertical.Angle60 = gain;
                    if (horizontal.Angle60 <= horizontal.Angle55)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 44)
                {
                    vertical.Angle65 = gain;
                    if (horizontal.Angle65 <= horizontal.Angle60)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 45)
                {
                    vertical.Angle70 = gain;
                    if (horizontal.Angle70 <= horizontal.Angle65)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 46)
                {
                    vertical.Angle75 = gain;
                    if (horizontal.Angle75 <= horizontal.Angle70)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 47)
                {
                    vertical.Angle80 = gain;
                    if (horizontal.Angle80 <= horizontal.Angle75)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 48)
                {
                    vertical.Angle85 = gain;
                    if (horizontal.Angle85 <= horizontal.Angle80)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                    if (horizontal.Angle90 <= horizontal.Angle85)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 49)
                {
                    vertical.Angle95 = gain;
                    if (horizontal.Angle95 >= horizontal.Angle90)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 50)
                {
                    vertical.Angle100 = gain;
                    if (horizontal.Angle100 >= horizontal.Angle95)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 51)
                {
                    vertical.Angle105 = gain;
                    if (horizontal.Angle105 >= horizontal.Angle100)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 52)
                {
                    vertical.Angle110 = gain;
                    if (horizontal.Angle110 >= horizontal.Angle105)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 53)
                {
                    vertical.Angle115 = gain;
                    if (horizontal.Angle115 >= horizontal.Angle110)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 54)
                {
                    vertical.Angle120 = gain;
                    if (horizontal.Angle120 >= horizontal.Angle115)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 55)
                {
                    vertical.Angle125 = gain;
                    if (horizontal.Angle125 >= horizontal.Angle120)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 56)
                {
                    vertical.Angle130 = gain;
                    if (horizontal.Angle130 >= horizontal.Angle125)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 57)
                {
                    vertical.Angle135 = gain;
                    if (horizontal.Angle135 >= horizontal.Angle130)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 58)
                {
                    vertical.Angle140 = gain;
                    if (horizontal.Angle140 >= horizontal.Angle135)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 59)
                {
                    vertical.Angle145 = gain;
                    if (horizontal.Angle145 >= horizontal.Angle140)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 60)
                {
                    vertical.Angle150 = gain;
                    if (horizontal.Angle150 >= horizontal.Angle145)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 61)
                {
                    vertical.Angle155 = gain;
                    if (horizontal.Angle155 >= horizontal.Angle150)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 62)
                {
                    vertical.Angle160 = gain;
                    if (horizontal.Angle160 >= horizontal.Angle155)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 63)
                {
                    vertical.Angle165 = gain;
                    if (horizontal.Angle165 >= horizontal.Angle160)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
                else if (deviceNum == 64)
                {
                    vertical.Angle170 = gain;
                    if (horizontal.Angle170 >= horizontal.Angle165)
                    {
                        throw new ATSPException("测试错误！测试的角度与增益不符合理论图形。");
                    }
                }
            }

            double halfAngle90 = horizontal.Angle90 / 2;

            if (horizontal.Angle10 <= halfAngle90 && halfAngle90 <= horizontal.Angle15)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle15 - horizontal.Angle10)) * (halfAngle90 - horizontal.Angle10)) + 10;
            }
            else if (horizontal.Angle15 <= halfAngle90 && halfAngle90 <= horizontal.Angle20)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle20 - horizontal.Angle15)) * (halfAngle90 - horizontal.Angle15)) + 15;
            }
            else if (horizontal.Angle20 <= halfAngle90 && halfAngle90 <= horizontal.Angle25)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle25 - horizontal.Angle20)) * (halfAngle90 - horizontal.Angle20)) + 20;
            }
            else if (horizontal.Angle25 <= halfAngle90 && halfAngle90 <= horizontal.Angle30)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle30 - horizontal.Angle25)) * (halfAngle90 - horizontal.Angle25)) + 25;
            }
            else if (horizontal.Angle30 <= halfAngle90 && halfAngle90 <= horizontal.Angle35)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle35 - horizontal.Angle30)) * (halfAngle90 - horizontal.Angle30)) + 30;
            }
            else if (horizontal.Angle35 <= halfAngle90 && halfAngle90 <= horizontal.Angle40)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle40 - horizontal.Angle35)) * (halfAngle90 - horizontal.Angle35)) + 35;
            }
            else if (horizontal.Angle40 <= halfAngle90 && halfAngle90 <= horizontal.Angle45)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle45 - horizontal.Angle40)) * (halfAngle90 - horizontal.Angle40)) + 40;
            }
            else if (horizontal.Angle45 <= halfAngle90 && halfAngle90 <= horizontal.Angle50)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle50 - horizontal.Angle45)) * (halfAngle90 - horizontal.Angle45)) + 45;
            }
            else if (horizontal.Angle50 <= halfAngle90 && halfAngle90 <= horizontal.Angle55)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle55 - horizontal.Angle50)) * (halfAngle90 - horizontal.Angle50)) + 50;
            }
            else if (horizontal.Angle55 <= halfAngle90 && halfAngle90 <= horizontal.Angle60)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle60 - horizontal.Angle55)) * (halfAngle90 - horizontal.Angle55)) + 55;
            }
            else if (horizontal.Angle60 <= halfAngle90 && halfAngle90 <= horizontal.Angle65)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle65 - horizontal.Angle60)) * (halfAngle90 - horizontal.Angle60)) + 60;
            }
            else if (horizontal.Angle65 <= halfAngle90 && halfAngle90 <= horizontal.Angle70)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle70 - horizontal.Angle65)) * (halfAngle90 - horizontal.Angle65)) + 65;
            }
            else if (horizontal.Angle70 <= halfAngle90 && halfAngle90 <= horizontal.Angle75)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle75 - horizontal.Angle70)) * (halfAngle90 - horizontal.Angle70)) + 70;
            }
            else if (horizontal.Angle75 <= halfAngle90 && halfAngle90 <= horizontal.Angle80)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle80 - horizontal.Angle75)) * (halfAngle90 - horizontal.Angle75)) + 75;
            }
            else if (horizontal.Angle80 <= halfAngle90 && halfAngle90 <= horizontal.Angle85)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle85 - horizontal.Angle80)) * (halfAngle90 - horizontal.Angle80)) + 80;
            }
            else if (horizontal.Angle85 <= halfAngle90 && halfAngle90 <= horizontal.Angle90)
            {
                horizontal.VisualAngleLeft = ((5 / (horizontal.Angle90 - horizontal.Angle85)) * (halfAngle90 - horizontal.Angle85)) + 85;
            }


            if (horizontal.Angle95 <= halfAngle90 && halfAngle90 <= horizontal.Angle90)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle90 - horizontal.Angle95)) * (halfAngle90 - horizontal.Angle95)) + 90;
            }
            else if (horizontal.Angle100 <= halfAngle90 && halfAngle90 <= horizontal.Angle95)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle95 - horizontal.Angle100)) * (halfAngle90 - horizontal.Angle100)) + 95;
            }
            else if (horizontal.Angle105 <= halfAngle90 && halfAngle90 <= horizontal.Angle100)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle100 - horizontal.Angle105)) * (halfAngle90 - horizontal.Angle105)) + 100;
            }
            else if (horizontal.Angle110 <= halfAngle90 && halfAngle90 <= horizontal.Angle105)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle105 - horizontal.Angle110)) * (halfAngle90 - horizontal.Angle110)) + 105;
            }
            else if (horizontal.Angle115 <= halfAngle90 && halfAngle90 <= horizontal.Angle110)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle110 - horizontal.Angle115)) * (halfAngle90 - horizontal.Angle115)) + 110;
            }
            else if (horizontal.Angle120 <= halfAngle90 && halfAngle90 <= horizontal.Angle115)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle115 - horizontal.Angle120)) * (halfAngle90 - horizontal.Angle120)) + 115;
            }
            else if (horizontal.Angle125 <= halfAngle90 && halfAngle90 <= horizontal.Angle120)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle120 - horizontal.Angle125)) * (halfAngle90 - horizontal.Angle125)) + 120;
            }
            else if (horizontal.Angle130 <= halfAngle90 && halfAngle90 <= horizontal.Angle125)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle125 - horizontal.Angle130)) * (halfAngle90 - horizontal.Angle130)) + 125;
            }
            else if (horizontal.Angle135 <= halfAngle90 && halfAngle90 <= horizontal.Angle130)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle130 - horizontal.Angle135)) * (halfAngle90 - horizontal.Angle135)) + 130;
            }
            else if (horizontal.Angle140 <= halfAngle90 && halfAngle90 <= horizontal.Angle135)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle135 - horizontal.Angle140)) * (halfAngle90 - horizontal.Angle140)) + 135;
            }
            else if (horizontal.Angle145 <= halfAngle90 && halfAngle90 <= horizontal.Angle140)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle140 - horizontal.Angle145)) * (halfAngle90 - horizontal.Angle145)) + 140;
            }
            else if (horizontal.Angle150 <= halfAngle90 && halfAngle90 <= horizontal.Angle145)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle145 - horizontal.Angle150)) * (halfAngle90 - horizontal.Angle150)) + 145;
            }
            else if (horizontal.Angle155 <= halfAngle90 && halfAngle90 <= horizontal.Angle150)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle150 - horizontal.Angle155)) * (halfAngle90 - horizontal.Angle155)) + 150;
            }
            else if (horizontal.Angle160 <= halfAngle90 && halfAngle90 <= horizontal.Angle155)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle155 - horizontal.Angle160)) * (halfAngle90 - horizontal.Angle160)) + 155;
            }
            else if (horizontal.Angle165 <= halfAngle90 && halfAngle90 <= horizontal.Angle160)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle160 - horizontal.Angle165)) * (halfAngle90 - horizontal.Angle165)) + 160;
            }
            else if (horizontal.Angle170 <= halfAngle90 && halfAngle90 <= horizontal.Angle165)
            {
                horizontal.VisualAngleRight = ((5 / (horizontal.Angle165 - horizontal.Angle170)) * (halfAngle90 - horizontal.Angle170)) + 165;
            }

            if (vertical.Angle10 <= halfAngle90 && halfAngle90 <= vertical.Angle15)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle15 - vertical.Angle10)) * (halfAngle90 - vertical.Angle10)) + 10;
            }
            else if (vertical.Angle15 <= halfAngle90 && halfAngle90 <= vertical.Angle20)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle20 - vertical.Angle15)) * (halfAngle90 - vertical.Angle15)) + 15;
            }
            else if (vertical.Angle20 <= halfAngle90 && halfAngle90 <= vertical.Angle25)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle25 - vertical.Angle20)) * (halfAngle90 - vertical.Angle20)) + 20;
            }
            else if (vertical.Angle25 <= halfAngle90 && halfAngle90 <= vertical.Angle30)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle30 - vertical.Angle25)) * (halfAngle90 - vertical.Angle25)) + 25;
            }
            else if (vertical.Angle30 <= halfAngle90 && halfAngle90 <= vertical.Angle35)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle35 - vertical.Angle30)) * (halfAngle90 - vertical.Angle30)) + 30;
            }
            else if (vertical.Angle35 <= halfAngle90 && halfAngle90 <= vertical.Angle40)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle40 - vertical.Angle35)) * (halfAngle90 - vertical.Angle35)) + 35;
            }
            else if (vertical.Angle40 <= halfAngle90 && halfAngle90 <= vertical.Angle45)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle45 - vertical.Angle40)) * (halfAngle90 - vertical.Angle40)) + 40;
            }
            else if (vertical.Angle45 <= halfAngle90 && halfAngle90 <= vertical.Angle50)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle50 - vertical.Angle45)) * (halfAngle90 - vertical.Angle45)) + 45;
            }
            else if (vertical.Angle50 <= halfAngle90 && halfAngle90 <= vertical.Angle55)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle55 - vertical.Angle50)) * (halfAngle90 - vertical.Angle50)) + 50;
            }
            else if (vertical.Angle55 <= halfAngle90 && halfAngle90 <= vertical.Angle60)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle60 - vertical.Angle55)) * (halfAngle90 - vertical.Angle55)) + 55;
            }
            else if (vertical.Angle60 <= halfAngle90 && halfAngle90 <= vertical.Angle65)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle65 - vertical.Angle60)) * (halfAngle90 - vertical.Angle60)) + 60;
            }
            else if (vertical.Angle65 <= halfAngle90 && halfAngle90 <= vertical.Angle70)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle70 - vertical.Angle65)) * (halfAngle90 - vertical.Angle65)) + 65;
            }
            else if (vertical.Angle70 <= halfAngle90 && halfAngle90 <= vertical.Angle75)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle75 - vertical.Angle70)) * (halfAngle90 - vertical.Angle70)) + 70;
            }
            else if (vertical.Angle75 <= halfAngle90 && halfAngle90 <= vertical.Angle80)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle80 - vertical.Angle75)) * (halfAngle90 - vertical.Angle75)) + 75;
            }
            else if (vertical.Angle80 <= halfAngle90 && halfAngle90 <= vertical.Angle85)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle85 - vertical.Angle80)) * (halfAngle90 - vertical.Angle80)) + 80;
            }
            else if (vertical.Angle85 <= halfAngle90 && halfAngle90 <= vertical.Angle90)
            {
                vertical.VisualAngleLeft = ((5 / (vertical.Angle90 - vertical.Angle85)) * (halfAngle90 - vertical.Angle85)) + 85;
            }


            if (vertical.Angle95 <= halfAngle90 && halfAngle90 <= vertical.Angle90)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle90 - vertical.Angle95)) * (halfAngle90 - vertical.Angle95)) + 90;
            }
            else if (vertical.Angle100 <= halfAngle90 && halfAngle90 <= vertical.Angle95)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle95 - vertical.Angle100)) * (halfAngle90 - vertical.Angle100)) + 95;
            }
            else if (vertical.Angle105 <= halfAngle90 && halfAngle90 <= vertical.Angle100)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle100 - vertical.Angle105)) * (halfAngle90 - vertical.Angle105)) + 100;
            }
            else if (vertical.Angle110 <= halfAngle90 && halfAngle90 <= vertical.Angle105)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle105 - vertical.Angle110)) * (halfAngle90 - vertical.Angle110)) + 105;
            }
            else if (vertical.Angle115 <= halfAngle90 && halfAngle90 <= vertical.Angle110)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle110 - vertical.Angle115)) * (halfAngle90 - vertical.Angle115)) + 110;
            }
            else if (vertical.Angle120 <= halfAngle90 && halfAngle90 <= vertical.Angle115)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle115 - vertical.Angle120)) * (halfAngle90 - vertical.Angle120)) + 115;
            }
            else if (vertical.Angle125 <= halfAngle90 && halfAngle90 <= vertical.Angle120)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle120 - vertical.Angle125)) * (halfAngle90 - vertical.Angle125)) + 120;
            }
            else if (vertical.Angle130 <= halfAngle90 && halfAngle90 <= vertical.Angle125)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle125 - vertical.Angle130)) * (halfAngle90 - vertical.Angle130)) + 125;
            }
            else if (vertical.Angle135 <= halfAngle90 && halfAngle90 <= vertical.Angle130)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle130 - vertical.Angle135)) * (halfAngle90 - vertical.Angle135)) + 130;
            }
            else if (vertical.Angle140 <= halfAngle90 && halfAngle90 <= vertical.Angle135)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle135 - vertical.Angle140)) * (halfAngle90 - vertical.Angle140)) + 135;
            }
            else if (vertical.Angle145 <= halfAngle90 && halfAngle90 <= vertical.Angle140)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle140 - vertical.Angle145)) * (halfAngle90 - vertical.Angle145)) + 140;
            }
            else if (vertical.Angle150 <= halfAngle90 && halfAngle90 <= vertical.Angle145)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle145 - vertical.Angle150)) * (halfAngle90 - vertical.Angle150)) + 145;
            }
            else if (vertical.Angle155 <= halfAngle90 && halfAngle90 <= vertical.Angle150)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle150 - vertical.Angle155)) * (halfAngle90 - vertical.Angle155)) + 150;
            }
            else if (vertical.Angle160 <= halfAngle90 && halfAngle90 <= vertical.Angle155)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle155 - vertical.Angle160)) * (halfAngle90 - vertical.Angle160)) + 155;
            }
            else if (vertical.Angle165 <= halfAngle90 && halfAngle90 <= vertical.Angle160)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle160 - vertical.Angle165)) * (halfAngle90 - vertical.Angle165)) + 160;
            }
            else if (vertical.Angle170 <= halfAngle90 && halfAngle90 <= vertical.Angle165)
            {
                vertical.VisualAngleRight = ((5 / (vertical.Angle165 - vertical.Angle170)) * (halfAngle90 - vertical.Angle170)) + 165;
            }

            horizontal.VisualAngleLeft -= 90;
            horizontal.VisualAngleRight -= 90;
            vertical.VisualAngleLeft -= 90;
            vertical.VisualAngleRight -= 90;

            TestResults testResults = new TestResults();
            testResults.Horizontal = horizontal;
            testResults.Vertical = vertical;

            if (acceptanceCondition.AxisGainMin <= horizontal.Angle90 && horizontal.Angle90 <= acceptanceCondition.AxisGainMax &&
                acceptanceCondition.HorizontalHalfGainMin <= Math.Abs(horizontal.VisualAngleLeft) && Math.Abs(horizontal.VisualAngleLeft) <= acceptanceCondition.HorizontalHalfGainMax &&
                acceptanceCondition.HorizontalHalfGainMin <= Math.Abs(horizontal.VisualAngleRight) && Math.Abs(horizontal.VisualAngleRight) <= acceptanceCondition.HorizontalHalfGainMax &&
                acceptanceCondition.VerticallHalfGainMin <= Math.Abs(vertical.VisualAngleLeft) && Math.Abs(vertical.VisualAngleLeft) <= acceptanceCondition.VerticallHalfGainMax &&
                acceptanceCondition.VerticallHalfGainMin <= Math.Abs(vertical.VisualAngleRight) && Math.Abs(vertical.VisualAngleRight) <= acceptanceCondition.VerticallHalfGainMax)
            {
                testResults.IsPass = true;
            }
            else
            {
                testResults.IsPass = false;
            }

            return testResults;
        }

        #endregion

        /// <summary>
        /// 检查投影机连接
        /// </summary>
        /// <returns>
        /// 设置桌面结果：
        ///     true 成功
        ///     false 失败
        /// </returns>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-08-26</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        public bool ProjectorCheckConnect()
        {
            return IProjectorCom.CheckConnect();
        }

        /// <summary>
        /// 投影机开机
        /// </summary>
        /// <returns>
        /// 设置桌面结果：
        ///     true 成功
        ///     false 失败
        /// </returns>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-08-26</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        public bool ProjectorStart()
        {
            return IProjectorCom.Start();
        }

        /// <summary>
        /// 投影机待机
        /// </summary>
        /// <returns>
        /// 设置桌面结果：
        ///     true 成功
        ///     false 失败
        /// </returns>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-08-26</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        public bool ProjectorAwait()
        {
            return IProjectorCom.Await();
        }

        /// <summary>
        /// 检查测试仪连接
        /// </summary>
        /// <returns>
        /// 设置桌面结果：
        ///     true 成功
        ///     false 失败
        /// </returns>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-08-26</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        public bool SerialCheckCOM()
        {
            return ISerialCom.CheckCOM();
        }

        /// <summary>
        /// 设置桌面
        /// </summary>
        /// <param name="color">颜色</param>
        /// <returns>
        /// 设置桌面结果：
        ///     true 成功
        ///     false 失败
        /// </returns>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-08-25</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        public bool SetDesktop(Color color)
        {
            if (!IProjectorCom.CheckConnect())
            {
                throw new ATSPException("无法连接投影机！请检查投影机连接。");
            }

            return IProjectorCom.SetDesktop(color);
        }

        /// <summary>
        /// 设置ADC参数指令
        /// </summary>
        /// <param name="range">量程参数</param>
        /// <param name="color">颜色</param>
        /// <returns>
        /// 是否设置成功 
        ///     true:成功
        ///     false:失败
        /// </returns>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-08-25</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        public bool SetADC(Range range, Color color)
        {
            if (!ISerialCom.CheckCOM())
            {
                throw new ATSPException("无法连接测试仪！请检查测试仪连接。");
            }

            if (!ISerialCom.SetADC(range))
            {
                return false;
            }

            Calibration calibration = new Calibration();
            calibration.Range = range;
            calibration.Color = color;
            if (!IPersistence.SaveCalibration(calibration))
            {
                return false;
            }

            return true;
        }

        /// <summary>
        /// 获取ADC-SENSOR数据指令
        /// </summary>
        /// <param name="deviceNum">设备号</param>
        /// <returns>采集值</returns>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-08-25</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        public ushort GetSensor(byte deviceNum)
        {
            if (!ISerialCom.CheckCOM())
            {
                throw new ATSPException("无法连接测试仪！请检查测试仪连接。");
            }

            return ISerialCom.GetSensor(deviceNum).CollectionValue;
        }

        /// <summary>
        /// 校准测试仪配置参数
        /// </summary>
        /// <param name="calibrationInstrumentBrightness">校准仪器亮度值</param>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-08-19</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        public void Adjust(CalibrationInstrumentBrightness calibrationInstrumentBrightness)
        {
            Precondition();

            if (!IProjectorCom.CheckConnect())
            {
                throw new ATSPException("校准失败！投影机未连接。");
            }

            if (!ISerialCom.CheckCOM())
            {
                throw new ATSPException("校准失败！测试仪未连接。");
            }

            Adust(calibrationInstrumentBrightness.DeviceNum, calibrationInstrumentBrightness.White, calibrationInstrumentBrightness.Black, Color.White);
            Adust(calibrationInstrumentBrightness.DeviceNum, calibrationInstrumentBrightness.Red, calibrationInstrumentBrightness.Black, Color.Red);
            Adust(calibrationInstrumentBrightness.DeviceNum, calibrationInstrumentBrightness.Green, calibrationInstrumentBrightness.Black, Color.Green);
            Adust(calibrationInstrumentBrightness.DeviceNum, calibrationInstrumentBrightness.Blue, calibrationInstrumentBrightness.Black, Color.Blue);

            if (!IProjectorCom.SetDesktop(Color.White))
            {
                throw new ATSPException("设置桌面失败！");
            }
        }

        /// <summary>
        /// 测试屏幕参数
        /// </summary>
        /// <param name="referenceBrightness">参考亮度值</param>
        /// <returns>测试结果的集合</returns>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-08-29</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        public TestResultsCollection Measure(ReferenceBrightness referenceBrightness)
        {
            Precondition();

            if (!IProjectorCom.CheckConnect())
            {
                throw new ATSPException("校准失败！投影机未连接。");
            }

            if (!ISerialCom.CheckCOM())
            {
                throw new ATSPException("校准失败！测试仪未连接。");
            }

            AcceptanceCondition acceptanceCondition = null;

            TestResultsCollection testResultsCollection = new TestResultsCollection();
            testResultsCollection.White = Measure(referenceBrightness.White, Color.White, acceptanceCondition);
            testResultsCollection.Red = Measure(referenceBrightness.Red, Color.Red, acceptanceCondition);
            testResultsCollection.Green = Measure(referenceBrightness.Green, Color.Green, acceptanceCondition);
            testResultsCollection.Blue = Measure(referenceBrightness.Blue, Color.Blue, acceptanceCondition);

            return testResultsCollection;
        }

        /// <summary>
        /// 线性度测试
        /// </summary>
        /// <param name="deviceNum">设备号</param>
        /// <param name="spacingCurrent">间隔电流</param>
        /// <returns>测试结果</returns>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-09-01</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        public Dictionary<ushort, ushort> LinearityMeasure(byte deviceNum, ushort spacingCurrent)
        {
            Dictionary<ushort, ushort> dictionary = new Dictionary<ushort, ushort>();

            ushort dacValue = 100;
            Dac dac = new Dac();
            do
            {
                dac.RedDAC = dacValue;
                dac.GreenDAC = dacValue;
                dac.BlueDAC = dacValue;
                IProjectorCom.SetDAC(dac);
                ushort sensorValue = GetSensor(deviceNum);
                dictionary.Add(dacValue, sensorValue);

                dacValue += spacingCurrent;
            } while (spacingCurrent < 230);

            return dictionary;
        }

        /// <summary>
        /// 重复性测试
        /// </summary>
        /// <param name="deviceNum">设备号</param>
        /// <param name="collectionTimes">采集次数</param>
        /// <returns>测试结果</returns>
        /// <remarks>
        ///     <创建人>邓穗捷</创建人>
        ///     <创建时间>2014-09-01</创建时间>
        ///     <修订人></修订人>
        ///     <修订时间></修订时间>
        ///     <修订说明></修订说明>
        /// </remarks>
        public Dictionary<int, ushort> RepeatabilityMeasure(byte deviceNum, int collectionTimes)
        {
            Dictionary<int, ushort> dictionary = new Dictionary<int, ushort>();

            for (int index = 0; index < collectionTimes; index++)
            {
                ushort sensorValue = GetSensor(deviceNum);
                dictionary.Add(index, sensorValue);
            }

            return dictionary;
        }
    }
}
